﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Crystal.Common.Model
Imports System.Data.SqlClient
Imports Crystal.CLL

Public Class cAddEditProject
#Region "Shared"
    Public cProjectID As Integer = 0
    Public cProjectName As String
    Public cClientID As Integer = 0
    Public cListing As String
    Public cProductTypeID As Integer = -1
    Public cSDD As Date
    Public cFDRD As Date
    Public cProjectStatusID As Integer
    Public cIsIgnored As Boolean
    Public cCompletionDate As Date
    Public cShareinIssue As Int64
    Public cShareOutstanding As Int64
    Public cFreeFloatValue As Int64
    Public cIsShareOutstandingAutomatic As Boolean
    Public cIsFreeFloat As Boolean
    Public cIsFreeFloatAutomatic As Boolean
    Public cCountryID As Integer
    Public cReportHistory As Integer
    Public cHasDDForm As String
    Public cHasDTCList As String
    Public cHasShareRegister As String
    Public cHasOfferingList As String
    Public cCreatedBy As Integer
    Public cModifiedBy As Integer
    Public Shared strConfiguration As String = CommonCLL.mstrConnectionstring
#End Region

#Region "Properties"
    Public Property ClientID() As Integer
        Get
            Return cClientID
        End Get
        Set(ByVal value As Integer)
            cClientID = value
        End Set
    End Property
    Public Property ProjectID() As Integer
        Get
            Return cProjectID
        End Get
        Set(ByVal value As Integer)
            cProjectID = value
        End Set
    End Property
    Public Property ProjectName() As String
        Get
            Return cProjectName
        End Get
        Set(ByVal value As String)
            cProjectName = value
        End Set
    End Property
    Public Property Listing() As String
        Get
            Return cListing
        End Get
        Set(ByVal value As String)
            cListing = value
        End Set
    End Property
    Public Property ProductTypeID() As Integer
        Get
            Return cProductTypeID
        End Get
        Set(ByVal value As Integer)
            cProductTypeID = value
        End Set
    End Property
    Public Property SDD() As Date
        Get
            Return cSDD
        End Get
        Set(ByVal value As Date)
            cSDD = value
        End Set
    End Property
    Public Property FDRD() As Date
        Get
            Return cFDRD
        End Get
        Set(ByVal value As Date)
            cFDRD = value
        End Set
    End Property
    Public Property ProjectStatusID() As Integer
        Get
            Return cProjectStatusID
        End Get
        Set(ByVal value As Integer)
            cProjectStatusID = value
        End Set
    End Property
    Public Property IsIgnored() As Boolean
        Get
            Return cIsIgnored
        End Get
        Set(ByVal value As Boolean)
            cIsIgnored = value
        End Set
    End Property
    Public Property CompletionDate() As Date
        Get
            Return cCompletionDate
        End Get
        Set(ByVal value As Date)
            cCompletionDate = value
        End Set
    End Property
    Public Property ShareinIssue() As Int64
        Get
            Return cShareinIssue
        End Get
        Set(ByVal value As Int64)
            cShareinIssue = value
        End Set
    End Property
    Public Property ShareOutstanding() As Int64
        Get
            Return cShareOutstanding
        End Get
        Set(ByVal value As Int64)
            cShareOutstanding = value
        End Set
    End Property
    Public Property FreeFloatValue() As Int64
        Get
            Return cFreeFloatValue
        End Get
        Set(ByVal value As Int64)
            cFreeFloatValue = value
        End Set
    End Property
    Public Property IsShareOutstandingAutomatic() As Boolean
        Get
            Return cIsShareOutstandingAutomatic
        End Get
        Set(ByVal value As Boolean)
            cIsShareOutstandingAutomatic = value
        End Set
    End Property
    Public Property IsFreeFloat() As Boolean
        Get
            Return cIsFreeFloat
        End Get
        Set(ByVal value As Boolean)
            cIsFreeFloat = value
        End Set
    End Property
    Public Property IsFreeFloatAutomatic() As Boolean
        Get
            Return cIsFreeFloatAutomatic
        End Get
        Set(ByVal value As Boolean)
            cIsFreeFloatAutomatic = value
        End Set
    End Property
    Public Property CountryID() As Integer
        Get
            Return cCountryID
        End Get
        Set(ByVal value As Integer)
            cCountryID = value
        End Set
    End Property
    Public Property ReportHistory() As Integer
        Get
            Return cReportHistory
        End Get
        Set(ByVal value As Integer)
            cReportHistory = value
        End Set
    End Property
    Public Property HasDDForm() As String
        Get
            Return cHasDDForm
        End Get
        Set(ByVal value As String)
            cHasDDForm = value
        End Set
    End Property
    Public Property HasDTCList() As String
        Get
            Return cHasDTCList
        End Get
        Set(ByVal value As String)
            cHasDTCList = value
        End Set
    End Property
    Public Property HasShareRegister() As String
        Get
            Return cHasShareRegister
        End Get
        Set(ByVal value As String)
            cHasShareRegister = value
        End Set
    End Property
    Public Property HasOfferingList() As String
        Get
            Return cHasOfferingList
        End Get
        Set(ByVal value As String)
            cHasOfferingList = value
        End Set
    End Property
    Public Property CreatedBy() As Integer
        Get
            Return cCreatedBy
        End Get
        Set(ByVal value As Integer)
            cCreatedBy = value
        End Set
    End Property
    Public Property ModifiedBy() As Integer
        Get
            Return cModifiedBy
        End Get
        Set(ByVal value As Integer)
            cModifiedBy = value
        End Set
    End Property
#End Region

#Region "Database Methods"
    Public Shared Function GetClientDetail(ByVal ClientID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ClientID", ClientID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetClientDetails", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetClients() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetClients", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetCountries() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetCountries", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetClientData() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_CLT_GetClientData", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetProjectStatus() As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetProjectStatus", CommandType.StoredProcedure, ReturnTypes.DataSet)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function GetRegionCountry(ByVal CountryID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@CountryID", CountryID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetRegionCountry", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function

    Public Function InsertProject() As Integer
        Dim Logmessage As New System.Text.StringBuilder
        Try
            Dim eReturnVal As ExecutionResult = Nothing
            Dim param(23) As SqlParameter
            param(0) = New SqlParameter("@ProjectID", cProjectID)
            param(1) = New SqlParameter("@ClientID", cClientID)
            param(2) = New SqlParameter("@ProjectName", ProjectName)
            param(3) = New SqlParameter("@Listing", Listing)
            param(4) = New SqlParameter("@ProductTypeID", ProductTypeID)
            If SDD = DateTime.MinValue Then
                param(5) = New SqlParameter("@SDD", DBNull.Value)
            Else
                param(5) = New SqlParameter("@SDD", SDD)
            End If
            If SDD = DateTime.MinValue Then
                param(6) = New SqlParameter("@FDRD", DBNull.Value)
            Else
                param(6) = New SqlParameter("@FDRD", FDRD)
            End If
            param(7) = New SqlParameter("@ProjectStatusID", ProjectStatusID)
            param(8) = New SqlParameter("@IsIgnored", IsIgnored)
            If CompletionDate = DateTime.MinValue Then
                param(9) = New SqlParameter("@CompletionDate", DBNull.Value)
            Else
                param(9) = New SqlParameter("@CompletionDate", CompletionDate)
            End If
            If ShareinIssue = 0 Then
                param(10) = New SqlParameter("@ShareinIssue", DBNull.Value)
            Else
                param(10) = New SqlParameter("@ShareinIssue", ShareinIssue)
            End If
            If ShareOutstanding = 0 Then
                param(11) = New SqlParameter("@ShareOutstanding", DBNull.Value)
            Else
                param(11) = New SqlParameter("@ShareOutstanding", ShareOutstanding)
            End If
            If FreeFloatValue = 0 Then
                param(12) = New SqlParameter("@FreeFloatValue", DBNull.Value)
            Else
                param(12) = New SqlParameter("@FreeFloatValue", FreeFloatValue)
            End If
            param(13) = New SqlParameter("@IsShareOutstandingAutomatic", IsShareOutstandingAutomatic)
            param(14) = New SqlParameter("@IsFreeFloat", IsFreeFloat)
            param(15) = New SqlParameter("@IsFreeFloatAutomatic", IsFreeFloatAutomatic)
            param(16) = New SqlParameter("@CountryID", CountryID)
            param(17) = New SqlParameter("@ReportHistory", ReportHistory)
            param(18) = New SqlParameter("@HasDDForm", HasDDForm)
            param(19) = New SqlParameter("@HasDTCList", HasDTCList)
            param(20) = New SqlParameter("@HasShareRegister", HasShareRegister)
            param(21) = New SqlParameter("@HasOfferingList", HasOfferingList)
            param(22) = New SqlParameter("@CreatedBy", CreatedBy)
            param(23) = New SqlParameter("@ModifiedBy", ModifiedBy)
            eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_InsertProject", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
            Return CType(eReturnVal.ResultObject, Integer)
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Shared Function GetProjectDetail(ByVal ProjectID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ProjectID", ProjectID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_GetProjectDetails", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function CheckCountry(ByVal ClientID As Integer) As DataSet
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ClientID", ClientID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_CheckProjectData", CommandType.StoredProcedure, ReturnTypes.DataSet, param)
        Return CType(eReturnVal.ResultObject, DataSet)
    End Function
    Public Shared Function CheckEnableIgnore(ByVal ProjectID As Integer) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ProjectID", ProjectID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_CheckEnableIgnore", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        Return CType(eReturnVal.ResultObject, Boolean)
    End Function

    Public Shared Function CheckClientProject(ByVal ClientID As Integer) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(0) As SqlParameter
        param(0) = New SqlParameter("@ClientID", ClientID)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_CheckClientProject", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        Return CType(eReturnVal.ResultObject, Boolean)
    End Function

    Public Shared Function IsProjectNameExist(ByVal clientID As Integer, ByVal SDD As Date) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(1) As SqlParameter
        param(0) = New SqlParameter("@clientID", clientID)
        param(1) = New SqlParameter("@SDD", SDD)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_PRJ_CheckProjectName", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        Return CType(eReturnVal.ResultObject, Boolean)
    End Function

    Public Shared Function AutoGeneratedColumns(ByVal pintProjectID As Integer, ByVal pintUserID As Integer) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim param(3) As SqlParameter
        param(0) = New SqlParameter("@ProjectID", pintProjectID)
        param(1) = New SqlParameter("@UserID", pintUserID)
        param(2) = New SqlParameter("@Result", DBResult.FAILED)
        param(3) = New SqlParameter("@ErrorMessage", String.Empty)
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CR_sp_DH_AutoCreateColumns", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        Return CType(eReturnVal.ResultObject, Boolean)
    End Function
#End Region
End Class
